<?php
namespace Common\Api; 
class changjiang implements ILogistics {

	private $apiurl="http://changjiangexpress.com/home/queryapi?number={number}&time={time}&code={code}";
	public function postservice($ary=array())
	{ 
		$arymsg=array('error'=>1,'errmsg'=>'数据有错误');
		if(!is_array($ary)||empty($ary['code'])){
			return $arymsg; 
		}
		
		$number=strtolower($ary['code']);
		$time= date("YmdHis");
		$code=strtolower(md5("".$number."#".$time."#SP"));
		 
	    $url=str_replace("{number}", $number, $this->apiurl);
	    $url=str_replace("{time}", $time, $url);
	    $url=str_replace("{code}", $code, $url);
	   
	    $ret= curlGet($url);
	    
	    if(empty($ret)){
	    	$arymsg=array('error'=>1,'errmsg'=>'获取物流信息错误');
	    	return $arymsg;  //"{'error':1,'errmsg':'获取物流信息错误'}"; 
	    }
	    
	    $data= json_decode($ret,true);
	    if(!is_array($data)){
	    	$arymsg=array('error'=>1,'errmsg'=>'获取物流信息无效数据');
	    	return $arymsg; // "{'error':1,'errmsg':'获取物流信息无效数据'}";
	    } 
	    
	    $arydata=array();
	    foreach ($data as $k=>$v){ 
	    	//$str .= ((empty($str)?"":",")."{'date':'".$v['Key']."','content':'".$v['Value']."'}"); 
	    	$arydata[]=array('date'=>$v['Key'],'content'=>$v['Value']);
	    }  
	    $json=array('error'=>0,'errmsg'=>'获取物流信息成功','rows'=>$arydata);    //"{\"error\":0,\"errmsg\":\"获取物流信息成功\",\"rows\":\"[".$str."]\"}";
	    return $json;
	} 
}

?>